const tencentcloud = require("tencentcloud-sdk-nodejs");

const SmsClient = tencentcloud.sms.v20190711.Client;
const models = tencentcloud.sms.v20190711.Models;

const Credential = tencentcloud.common.Credential;
const ClientProfile = tencentcloud.common.ClientProfile;
const HttpProfile = tencentcloud.common.HttpProfile;

module.exports = {
    SendSms:(tel,code)=>{
        let cred = new Credential("AKIDh50ewJXBD1a085zqfHdiZDg1EMQqqto6", "d196xZuyKhura74k8UtWsy53mFxurgKk");
        let httpProfile = new HttpProfile();
        httpProfile.endpoint = "sms.tencentcloudapi.com";
        let clientProfile = new ClientProfile();
        clientProfile.httpProfile = httpProfile;
        let client = new SmsClient(cred, "", clientProfile);
        
        let req = new models.SendSmsRequest();
        let params = {
            "PhoneNumberSet": [
                `+86${tel}`
            ],
            "TemplateID": "463239",
            "Sign": "U你校园",
            "TemplateParamSet": [
                code
            ],
            "SmsSdkAppid": "1400282547"
        };
        req.from_json_string(JSON.stringify(params));
        
        client.SendSms(req, function(errMsg, response) {
            if (errMsg) {
                return errMsg
            }
            return response.to_json_string()
        });
    }
}

